home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8766 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: feed.umontreal.ca!epsom!not-for-mail
  2. From: pigeons@JSP.UMontreal.CA (PIGEON Steven)
  3. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 26 Feb 1996 16:27:25 GMT
  6. Organization: Universite de Montreal
  7. Distribution: world
  8. Message-ID: <4gsn1d$ia@epervier.CC.UMontreal.CA>
  9. References: <4fr8be$ass@news.iconn.net> <4g2agv$29r@clarknet.clark.net>
  10. NNTP-Posting-Host: epsom.jsp.umontreal.ca
  11. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  12.  
  13. Harlan Messinger (gusty@clark.net) wrote:
  14. : void getLastFactorialDigits(int results[], // assume sufficient space
  15. :                                            // was preallocated (n+1 bytes)
  16. :                 int n) {
  17. :     results[0] = 1;
  18. :     results[1] = 1;
  19. :     for (int i = 2; i <= n; ++i) {
  20. :         results[i] = results[i - 1] * i;
  21. :         while (results[i] % 10 == 0)
  22. :             results[i] /= 10;
  23. :         results[i] = results[i] % 10;
  24. :     }
  25. :     return;
  26. : }
  27.  
  28.  
  29. Ah a! In PASCAL!!! :-) This is a Pascal group!
  30.  
  31.  
  32.  
  33.  function zerofacto(n:integer):integer;
  34.  var s,j,i:longint;
  35.   begin
  36.    s:=1;
  37.    j:=1;
  38.    i:=0;
  39.  
  40.    while (j<=n) do
  41.     begin
  42.      s:=s*j;
  43.      while ( (s>10) and (s mod 10=0)) do
  44.       begin
  45.        s:=s div 10;
  46.        inc(i);
  47.       end;
  48.      s:=s mod 10;
  49.      inc(j);
  50.     end;
  51.     zerofacto:=s mod 10;
  52.   end;
  53.  
  54.  
  55.  
  56. ---------------------------------------------------------------------------
  57. Steven Pigeon,              http://www.iro.umontreal.ca/people/pigeon
  58. graduate student
  59.